package com.dongao.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.dongao.activity.service.DownloadService;
import com.dongao.model.Course;
import com.dongao.model.CourseWare;
import com.dongao.model.Mp3Info;

public class DownloadActivity extends ListActivity {

	private List<Mp3Info> mp3Infos = new ArrayList<Mp3Info>();
	private Course course;
	private List<CourseWare> courseWares;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_download_course);
		
		Mp3Info mp3Info = new Mp3Info();
		mp3Info.setMp3Name("放心不下");
		
		mp3Infos.add(mp3Info);

		List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		for (Mp3Info mp3 : mp3Infos) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("name", mp3.getMp3Name());
//			map.put("mp3_size", mp3.getMp3Size());
			list.add(map);
		}
		

		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
				R.layout.simple_list_item, new String[] { "name"},
				new int[] { R.id.name});
		
		setListAdapter(simpleAdapter);
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
//		
		Mp3Info mp3Info = mp3Infos.get(position);
		Intent intent = new Intent();
		intent.putExtra("mp3Info", mp3Info);
		intent.setClass(this, DownloadService.class);
		System.out.println("启动下载服务");
		startService(intent);
		super.onListItemClick(l, v, position, id);
	}
}
